//-----------------------------------------------------------------------
// <copyright file="ShippingLineDAO.cs" company="Pyramid Consulting">
//     Copyright (c) Pyramid Consulting. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
	
using System;
using System.Data;
using MIMS.WRS.Entities;
using MyFramework;
using MyFramework.Data;
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace MIMS.WRS.Data
{	
	public class ShippingLineDAO : ShippingLineDAOBase
	{
		public ShippingLineDAO()
		{
		}

		public virtual ShippingLine GetShippingLineByCode(string code)
		{            
			try
			{
				Database database = DatabaseFactory.CreateDatabase();
				DBCommandWrapper dbCommandWrapper = database.GetStoredProcCommandWrapper("spShippingLineGetByCode");
                
				dbCommandWrapper.AddInParameter("@code", DbType.AnsiString, code);
                
				ShippingLine shippingLine =  null;
				using (IDataReader reader = DataAccessHelper.ExecuteReader(database, dbCommandWrapper))
				{
					if (reader.Read())
					{
						shippingLine = CreateShippingLineFromReader(reader);
						reader.Close();
					}
				}
				return shippingLine;
			}
			catch (Exception ex)
			{
				// log this exception
				Logger.Error(ex);
				// wrap it and rethrow
				throw new DataAccessException(SR.DataAccessGetShippingLineException, ex);
			}
		}
	}
}
